package com.opages.netty.demo.netty.stickybag;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * @author daizhong.liu
 * @create 2021-12-15 15:09
 **/
public class MessageEncoder extends MessageToByteEncoder<MessageProtocol> {
    private int count;
    @Override
    protected void encode(ChannelHandlerContext ctx, MessageProtocol msg, ByteBuf out) throws Exception {
        System.err.println("MessageEncoder调用");
        out.writeInt(msg.getLen());
        out.writeBytes(msg.getContent());
        System.err.println(ctx.channel().localAddress()+"调用次数:"+(++count));
    }
}
